/* -----------------------------------------------------------------------
 * Random tester for adventurer kingdom card
 * Include the following lines in your makefile:
 *
 * randomtestadventurer: randomtestadventurer.c dominion.o rngs.o
 *      gcc -o randomtestadventurer.out -g  randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */
#include "dominion.h"
#include "dominion_helpers.h"
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <assert.h>
#include<time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0


//Random test Adventurer

//tests
//treasure from deck

//deck empty shuffle in discard


//all drawn cards discarded


int main(int argc, char *argv[])
{
    srand(time(NULL));
	
	int i, j;
    int seed = 1000;
    int numPlayer = rand() % 4;
	int tests = rand() % MAX_HAND;
    int r, one, two;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int handCount = 5;
	int adventurers[MAX_HAND];
	int treasures[MAX_HAND];
	
	//begin tests
	printf("Starting tests...\n");
	for(i = 0; i < tests; i++){
		for(j = 0; j < numPlayer; j++){
		
			for (i = 0; i < MAX_HAND; i++)
			{
				adventurers[i] = adventurer;
				treasures[i] = adventurer;
			}
			
			one = rand() % 5;
			two = one + 3;
			treasures[one] = copper;
			treasures[two] = copper;
			
			
			//test with 2 treasures in deck
			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			assert(r == 0); 							//make sure initializes properly
			memcpy(G.hand[j], adventurers, sizeof(int) * handCount); // set all the cards to adventurer
			memcpy(G.deck[j], treasures, sizeof(int) * handCount); // set all the cards to copper
			G.deckCount[j] = 10;
			G.whoseTurn = j;
#if (NOISY_TEST == 1)
	printf("handCount: %d, deckCount: %d, phase: %d, whoseturn: %d\n", G.handCount[0], G.deckCount[0], G.phase, G.whoseTurn);
#endif
			if(DEBUG){
				for (i = 0; i < handCount; i++)
				{
					printf("%d\n", G.hand[0][i]);
				}
			}
			
			r = playCard(0, 0, 0, 0, &G);		// call Adventurer effect
#if (NOISY_TEST == 1)
	printf("\ntest with 2 treasure in deck.\n");
	printf("cardEffect return is %d, expected 0.\n", r);	//drawCard's return
	printf("cards drawn: %d and %d, expected %d and %d\n", G.hand[j][G.handCount[j]-2], G.hand[j][G.handCount[j]-1], copper, copper);
#endif
			assert(r == 0);
			assert(G.hand[j][G.handCount[j]-2] == copper && G.hand[j][G.handCount[j]-1] == copper);
			
			
/*			//test with 1 treasures in deck. requires shuffle
			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			memcpy(G.hand[j], adventurers, sizeof(int) * handCount); // set all the cards to adventurer
			memcpy(G.deck[j], oneTreasure, sizeof(int) * handCount); // set all the cards to copper
			G.whoseTurn = j;
#if (NOISY_TEST == 1)
	printf("handCount: %d, deckCount: %d, phase: %d, whoseturn: %d\n", G.handCount[0], G.deckCount[0], G.phase, G.whoseTurn);
#endif
			if(DEBUG){
				for (i = 0; i < handCount; i++)
				{
					printf("%d\n", G.hand[0][i]);
				}
			}
			
			r = playCard(0, 0, 0, 0, &G);		// call Adventurer effect
#if (NOISY_TEST == 1)
	printf("\ntest with 1 treasure in deck.\n");
	printf("cardEffect return is %d, expected 0.\n", r);	//drawCard's return
	printf("cards drawn: %d and %d, expected %d and %d\n", G.hand[j][4], G.hand[j][5], copper, copper);
#endif
			assert(r == 0);
			assert(G.hand[j][G.handCount[j]-2] == copper && G.hand[j][G.handCount[j]-1] == copper);
			
			
			//test with 2 treasures in discard and empty deck. requires shuffle
			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			memcpy(G.hand[j], adventurers, sizeof(int) * handCount); // set all the cards to adventurer
			memcpy(G.discard[j], coppers, sizeof(int) * handCount); // set all the cards to copper
			G.whoseTurn = j;
			G.deckCount[j] = 0;
#if (NOISY_TEST == 1)
	printf("handCount: %d, deckCount: %d, phase: %d, whoseturn: %d\n", G.handCount[0], G.deckCount[0], G.phase, G.whoseTurn);
#endif
			if(DEBUG){
				for (i = 0; i < handCount; i++)
				{
					printf("%d\n", G.hand[0][i]);
				}
			}
			
			r = playCard(0, 0, 0, 0, &G);		// call Adventurer effect
#if (NOISY_TEST == 1)
	printf("\ntest with no cards in deck.\n");
	printf("cardEffect return is %d, expected 0.\n", r);	//drawCard's return
	printf("cards drawn: %d and %d, expected %d and %d\n", G.hand[j][4], G.hand[j][5], copper, copper);
#endif
			//assert(r == 0);
			//assert(G.hand[j][G.handCount[j]] == copper && G.hand[j][G.handCount[j]-1] == copper);
			
*/

			
		}
	}

	printf("All tests completed successfully...\n");
	
    return 0;                  
}                              